package com.zztl.infiniteBand.presenter

import android.content.Context
import android.text.TextUtils
import com.zztl.infiniteBand.R
import com.zztl.infiniteBand.model.NoDataResponseBean
import com.zztl.infiniteBand.net.FilterSubscriber
import com.zztl.infiniteBand.net.RetorfitServiceManger
import com.zztl.infiniteBand.net.converter.DataConverter
import com.zztl.infiniteBand.net.requestBean.RegisterRequest
import com.zztl.infiniteBand.ui.view.mvpview.RegisterView
import com.zztl.infiniteBand.util.UiUtils
import com.zztl.infiniteBand.util.toast


/**
 * @desc
 * @auth ${user} swl
 * @time 2018/6/11  16:55
 */
class RegisterPresenter : BaseCodePresenter<RegisterView>() {

    fun register(registerRequest: RegisterRequest, context: Context) {
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService
                .register(DataConverter.instance.toJson(registerRequest)))
                .subscribe(object : FilterSubscriber<NoDataResponseBean>(context) {
                    override fun success(bean: NoDataResponseBean) {
                        val registerView = view!! as RegisterView
                        registerView.registerSuccess()
                    }

                    override fun fail() {
                        super.fail()
                        val registerView = view!! as RegisterView
                        registerView.registerFail()
                    }
                }))
    }

    fun check(phone: String, pwd: String, code: String,nickname:String): Boolean {
        //        boolean isCorrect = true;
        if (TextUtils.isEmpty(phone)) {
            UiUtils.context.toast(UiUtils.getString(R.string.手机号不能为空))
            return false
        }
        /* if(!TextCheckUtil.isMobileNO(mPhone)){
            ToastUtils.show(this, "手机号格式不正确");
            return false;
        }*/
        if (TextUtils.isEmpty(code)) {
            UiUtils.context.toast(UiUtils.getString(R.string.验证码不能为空))
            return false
        }
        if(TextUtils.isEmpty(nickname)){
            UiUtils.context.toast(UiUtils.getString(R.string.姓名不能为空))
            return false
        }
        if (TextUtils.isEmpty(pwd)) {
            UiUtils.context.toast(UiUtils.getString(R.string.密码不能为空))
            return false
        }
        if (pwd.length < 6 || pwd.length > 16) {
            UiUtils.context.toast(UiUtils.getString(R.string.密码长度为6到16位))
            return false
        }
        return true
    }


}
